package com.heima.article.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.StatisticsDto;
import com.heima.model.wemedia.dtos.WmCommentPageReqDTO;
import com.heima.model.wemedia.vos.WmCommentVo;
import org.apache.commons.net.nntp.Article;
import com.heima.model.wemedia.dtos.WmCommentLikeDTO;
import com.heima.model.wemedia.dtos.WmCommentListPageReqDTO;
import com.heima.model.wemedia.dtos.WmCommentUpdateStatusDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author 陈辉
 * @data 2023 15:11
 */
@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApArticleService apArticleService;

    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @PostMapping("/api/v1/article/save")
    @Override
    public ResponseResult saveArticle(ArticleDto dto) {

        return apArticleService.saveOrUpdateArticle(dto);
    }

    /**
     * 根据时间范围统计点赞数量和收藏数量
     *
     * @param
     * @param
     * @param
     * @param beginDateTime
     * @param endDateTime
     * @return
     */
    @Override
    @GetMapping("/api/v1/article/queryLikesAndConllections")
    public ResponseResult queryLikesAndConllections(@RequestParam Integer authorId, @RequestParam LocalDateTime beginDateTime, @RequestParam LocalDateTime endDateTime) {
        return apArticleService.queryLikesAndConllections(authorId, beginDateTime, endDateTime);
    }

    ;

    /**
     * 获取文章
     *
     * @param articleId
     * @return
     */
    @Override
    @GetMapping("/api/v1/article/{articleId}")
    public ApArticle getArticle(Long articleId) {
        return apArticleService.getById(articleId);
    }


    /**
     * 更新文章评论状态
     *
     * @param wmCommentUpdateStatusDTO
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/getCommentVo/updateStatus")
    public ResponseResult updateCommentStatus(@RequestBody WmCommentUpdateStatusDTO wmCommentUpdateStatusDTO) {
        return apArticleService.updateCommentStatus(wmCommentUpdateStatusDTO);
    }

    /**
     * 查看文章评论列表
     *
     * @param wmCommentListPageReqDTO
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/comment/list")
    public ResponseResult commentList(@RequestBody WmCommentListPageReqDTO wmCommentListPageReqDTO) {
        return apArticleService.commentList(wmCommentListPageReqDTO);
    }

    /**
     * 自媒体端评论点赞
     *
     * @param wmCommentLikeDTO
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/comment/like")
    public ResponseResult commentLike(@RequestBody WmCommentLikeDTO wmCommentLikeDTO, @RequestParam Integer authorId) {
        return apArticleService.commentLike(wmCommentLikeDTO, authorId);
    }


    /**
     * 根据文章id获取文章配置
     *
     * @param articleId
     * @return
     */
    @GetMapping("/api/v1/article/findArticleConfigByArticleId/{articleId}")
    @Override
    public ResponseResult findArticleConfigByArticleId(@PathVariable Long articleId) {
        ApArticleConfig apArticleConfig = apArticleConfigService.getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
        return ResponseResult.okResult(apArticleConfig);
    }

    /**
     * 根据用户id获取文章信息
     *
     * @param statisticsDto
     * @return
     */
    @PostMapping("/api/v1/article/statistics/newsPage")
    @Override
    public PageResponseResult newPage(@RequestBody StatisticsDto statisticsDto) {
        return apArticleService.newPage(statisticsDto);
    }

    /**
     * 文章表中评论+1
     *
     * @param entryId
     */
    @Override
    @GetMapping("/api/v1/article/comment/addOne/{entryId}")
    public void addOneComment(@PathVariable("entryId") Long entryId) {
        apArticleService.addOneComment(entryId);
    }

    /**
     * 删除指定数量的评论
     *
     * @param num
     */
    @Override
    @GetMapping("/api/v1/article/comment/delete/{num}/{articleId}")
    public void deleteCommentNum(@PathVariable("num") Integer num, @PathVariable("articleId") Long articleId) {
        apArticleService.deleteCommentNum(num, articleId);
    }

    /**
     * 通过文章id获取文章信息
     *
     * @param articleId
     * @return
     */
    @Override
    @GetMapping("/api/v1/article/comment/find/{articleId}")
    public ApArticle findByArticleId(@PathVariable("articleId") Long articleId) {
        return apArticleService.findByArticleId(articleId);
    }


}
